class Event {
  constructor() {
    /*
  * this.events = {
    click: [f1,f2,f3],
    mousemove: [f1,f2,f3]
  }
  */
    this.events = {};
  }
  // 添加相应的事件处理
  on(evnet, fn) {
    if (!this.events[evnet]) {
      this.events[evnet] = [];
    }
    this.events[evnet].push(fn);
  }

  // 删除相应的事件处理
  off(evnet, fn) {
    if (this.events[evnet]) {
      this.events[evnet] = this.events[evnet].filter(
        (item) => fn != item
      );
    }
  }

  // 触发相应的事件处理
  dispatch(event, ...arg) {
    if (this.events[event]) {
      this.events[event].forEach((item) => {
        item.call(this, ...arg); // 从window => 指向实例化对象
      });
    }
  }
}